package br.com.alugargaragem.domain.login.repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import br.com.alugargaragem.domain.login.model.Login;
import br.com.alugargaragem.domain.login.model.LoginId;
import br.com.alugargaragem.infrastructure.dao.AlugaGaragemJpaDAO;

@Component("loginRepository")
public class LoginRepositoryDAO extends AlugaGaragemJpaDAO<Login, LoginId>
		implements LoginRepository {

	private static final String FIND_ALL = "findAll";
	private static final String FIND_BY_EMAIL_PASSWORD = "findByEmailPassword";
	private static final String FIND_BY_EMAIL = "findByEmail";

	@Override
	public Collection<? extends Login> findAll() {
		return this.find(FIND_ALL);
	}

	@Override
	public Login findByEmail(Login login) {
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("email", login.getEmail());
		return this.findSingleResult(FIND_BY_EMAIL, parameters);
	}

	@Override
	public Login findByEmailPassword(Login login) {
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("email", login.getEmail());
		parameters.put("password", login.getPassword());
		return this.findSingleResult(FIND_BY_EMAIL_PASSWORD, parameters);
	}

}
